package com.ruoyi.carShopService.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.domain.CarShopCoupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.carShopService.service.ICarShopCouponService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 优惠券信息Controller
 * 
 * @author ruoyi
 * @date 2024-09-14
 */
@RestController
@RequestMapping("/coupon")
public class CarShopCouponController extends BaseController
{
    @Autowired
    private ICarShopCouponService carShopCouponService;

    /**
     * 查询优惠券信息列表
     */
    //@RequiresPermissions("carShopService:coupon:list")
    @GetMapping("/list")
    public TableDataInfo list(CarShopCoupon carShopCoupon)
    {
        startPage();
        List<CarShopCoupon> list = carShopCouponService.selectCarShopCouponList(carShopCoupon);
        return getDataTable(list);
    }

    /**
     * 导出优惠券信息列表
     */
    //@RequiresPermissions("carShopService:coupon:export")
    @Log(title = "优惠券信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarShopCoupon carShopCoupon)
    {
        List<CarShopCoupon> list = carShopCouponService.selectCarShopCouponList(carShopCoupon);
        ExcelUtil<CarShopCoupon> util = new ExcelUtil<CarShopCoupon>(CarShopCoupon.class);
        util.exportExcel(response, list, "优惠券信息数据");
    }

    /**
     * 获取优惠券信息详细信息
     */
    //@RequiresPermissions("carShopService:coupon:query")
    @GetMapping(value = "/{couId}")
    public AjaxResult getInfo(@PathVariable("couId") Long couId)
    {
        return success(carShopCouponService.selectCarShopCouponByCouId(couId));
    }

    /**
     * 新增优惠券信息
     */
    //@RequiresPermissions("carShopService:coupon:add")
    @Log(title = "优惠券信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarShopCoupon carShopCoupon)
    {
        return toAjax(carShopCouponService.insertCarShopCoupon(carShopCoupon));
    }

    /**
     * 修改优惠券信息
     */
    //@RequiresPermissions("carShopService:coupon:edit")
    @Log(title = "优惠券信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarShopCoupon carShopCoupon)
    {
        return toAjax(carShopCouponService.updateCarShopCoupon(carShopCoupon));
    }

    /**
     * 删除优惠券信息
     */
    //@RequiresPermissions("carShopService:coupon:remove")
    @Log(title = "优惠券信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{couIds}")
    public AjaxResult remove(@PathVariable Long[] couIds)
    {
        return toAjax(carShopCouponService.deleteCarShopCouponByCouIds(couIds));
    }
}
